package com.wgzx.modbus.entity.response;

import com.wgzx.modbus.constant.FunctionCode;
import com.wgzx.modbus.entity.ModbusRsp;
import io.netty.buffer.ByteBuf;
import lombok.Getter;

/**
 * 请求报文：<br/>
 * 功能码：写多个寄存器 1个字节 0x10 <br/>
 * 起始地址：2个字节0x0000至0xFFFF <br/>
 * 寄存器数量：2个字节0x0001至0x007B <br/>
 * 字节数：1个字节 <br/>
 * 寄存器值：N个字节 <br/>
 *
 * 响应报文：<br/>
 * 功能码：1个字节 0x10 <br/>
 * 起始地址：2个字节0x0000至0xFFFF <br/>
 * 寄存器数量：2个字节0x0001至0x007B <br/>
 *
 * 错误响应：<br/>
 * 差错码：1个字节0x8F <br/>
 * 异常码：1个字节01或02或03或04 <br/>
 *
 * 示例报文：<br/>
 * Rx:00 01 00 00 00 1B(长度) FF(标识) 10(功能码) 00 00(起始地址) 00 0A(寄存器数量) 14(字节数:20) FF FF(值1) F0 F0(值2) 0F 0F(值3) 00 00(值N) 00 00 00 00 00 00 00 00 00 00 00 00 <br/>
 * Tx:00 01 00 00 00 06(长度) FF(标识) 10(功能码) 00 00(起始地址) 00 0A(寄存器数量) <br/>
 *
 * @author gexin
 */
@Getter
public class WriteMultipleRegistersResponse extends ModbusRsp {

    private int address;
    private int value;

    public WriteMultipleRegistersResponse(FunctionCode functionCode) {
        super(functionCode);
    }

    @Override
    public String toString() {
        return "WriteMultipleRegistersResponse{" + "startingAddress=" + address + ", quantityOfRegisters=" + value + '}';
    }

    @Override
    public void decode(ByteBuf buffer) {
        address = buffer.readUnsignedShort();
        value = buffer.readUnsignedShort();
    }
}
